home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 20 / Cream of the Crop 20 (Terry Blount) (1996).iso / program / commio0b.zip / TEXTDEV.PAS < prev    next >
Pascal/Delphi Source File  |  1996-05-05  |  4KB  |  110 lines

  1. unit textdev;
  2. {
  3.           This unit is a companion to the COMMIO communications unit.
  4.                 Written by Jason Morriss a.k.a. Lief O'Pardy
  5.  
  6.                   Copyright (C) 1995,1996 by Jason Morriss
  7.  
  8.   Including this unit in your main program source code allows you to use
  9.   TP's "write" & "writeln" procedures to do any output.  It will output to
  10.   the remote and the local sides, just like if you were using the included
  11.   output routines in the COMMIO unit!
  12.   The only limitation on this method is that you can't put color/animation
  13.   codes in the string (like the putstr() proc), if you do they will be
  14.   displayed on both screens as normal text, you have to change the colors
  15.   by using the SetColor, SetFore, or SetBack procedures.  Otherwise you must
  16.   use the "Putstr()" procedure to do color changing/animation within the
  17.   string.  The syntax for using this method is:
  18.     write(SIO,'This is string 1.',' This is another...', ' A number:',12);
  19.           ^^^- that SIO file is the important element to use this method.
  20.   You basically use the SIO variable just like if it were an actual text file.
  21.   But certain procedures like "close,append,reset,rewrite,etc" don't do
  22.   anything when called with SIO. (Rewrite actually DOES do something, but
  23.   its handled automatically by this unit, and once Rewrite is called once,
  24.   successive calls don't do anything more).  The SIO file does not need to
  25.   be closed, TP will do that on its own when the program exits.
  26.   Do NOT try to use READLN() with the IO variable, it'll do NOTHING, and
  27.   you'll get unpredicted results from it.
  28. }
  29. interface
  30.  
  31. uses crt,dos,commio;
  32.  
  33. var
  34.   IOBuf : array[0..511] of char;
  35.   SIO : text;
  36.  
  37. {Procedure AssignIO;}
  38.  
  39. implementation
  40.  
  41.  
  42. {───────────────────────────────────────────────────────────────────────────}
  43. function IOnothing(var F:textrec):integer; far;
  44. begin
  45.   IOnothing:=0;
  46. end;
  47. {───────────────────────────────────────────────────────────────────────────}
  48. function IOinput(var F:textrec):integer; far;
  49. begin
  50.   IOinput:=0;
  51. end;
  52. {───────────────────────────────────────────────────────────────────────────}
  53. function IOoutput(var F:textrec):integer; far;
  54. var i:word; {s:string;{}
  55. begin
  56.   with f do begin
  57.     i:=0;
  58. {}{    if BufPos>0 then begin
  59.       move(BufPtr^,s[1],BufPos); s[0]:=char(BufPos);
  60.       putstr(s);
  61.     end;{buffer must be 255 bytes big for this loop!}
  62.     while i<BufPos do begin
  63.       sioWriteC(BufPtr^[i]);
  64.       inc(i);
  65.     end;{}
  66.     BufPos:=0;
  67.   end;
  68.   IOoutput:=0;
  69. end;
  70. {───────────────────────────────────────────────────────────────────────────}
  71. function IOclose(var F:textrec):integer; far;
  72. begin
  73.   IOclose:=0;
  74. end;
  75. {───────────────────────────────────────────────────────────────────────────}
  76. function IOopen(var F:textrec):integer; far;
  77. begin
  78.   with f do begin
  79.     if mode=fminput then begin
  80.       InOutFunc:=@IOnothing;
  81.       FlushFunc:=@IOnothing;
  82.     end else begin
  83.       mode:=fmoutput;
  84.       InOutFunc:=@IOoutput;
  85.       FlushFunc:=@IOoutput;
  86.     end;
  87.     CloseFunc:=@IOnothing;
  88.   end;
  89.   IOopen:=0;
  90. end;
  91. {───────────────────────────────────────────────────────────────────────────}
  92. Procedure AssignIO;
  93. begin
  94.   FillChar(SIO, sizeof(SIO), 0);
  95.   with textrec(SIO) do begin
  96.     handle:=$FFFF;
  97.     mode:=fmclosed;
  98.     bufsize:=sizeof(buffer);
  99.     bufptr:=@buffer;
  100.     OpenFunc:=@IOopen;
  101.   end;
  102. end;
  103. {───────────────────────────────────────────────────────────────────────────}
  104.  
  105. begin
  106.   AssignIO;
  107.   SetTextBuf(SIO,IOBuf);{}
  108.   Rewrite(SIO);
  109. end.
  110.